package com.kun.controller;

import com.kun.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private RestTemplate restTemplate;

//    private static final String REST_URL_PREFIX = "http://localhost:8001";
    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-DEPT";

    @GetMapping("/queryAllList")
    public Object queryAllList() {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/queryAllList", Object.class);
    }

    @GetMapping("/queryById/{id}")
    public Object queryById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/" + id, Dept.class);
    }

    @PostMapping("/add")
    public Object add(@RequestBody Dept dept) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/add", dept, Object.class);
    }

    @PostMapping("/update")
    public Object update(@RequestBody Dept dept) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/dept/update", dept, Object.class);
    }

    @PostMapping("/delete/{id}")
    public Object delete(@PathVariable("id") Long id) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/dept/delete/" + id, Object.class);
    }







}
